package com.swz.dcrm.adpter;

import android.content.Context;
import android.widget.TextView;

import com.swz.dcrm.R;
import com.swz.dcrm.base.ViewHolder;
import com.swz.dcrm.model.Announcement;
import com.swz.dcrm.util.DateUtils;

import java.util.Date;
import java.util.List;

public class MessageAdapter extends CustomAdapter<Announcement> {
    public MessageAdapter(Context context, List<Announcement> datas) {
        super(context, R.layout.item_announcement, datas);
    }
    @Override
    protected void convert(ViewHolder holder, Announcement announcement, int position) {
        holder.setText(R.id.tv_content,announcement.getContent());
        if(DateUtils.dateParse(announcement.getEndTime(),"yyyy-MM-dd").getDay()==new Date().getDay()){
            holder.setText(R.id.tv_date,"今天  "+DateUtils.dateFormat(announcement.getEndTime(),"HH:mm"));

        }else {
            holder.setText(R.id.tv_date,DateUtils.dateFormat(announcement.getEndTime(),"yyyy-MM-dd HH:mm"));
        }
        holder.itemView.setClickable(false);
        TextView textView=holder.getView(R.id.tv_content);
        textView.setCompoundDrawables(null, null, null, null);
        holder.itemView.setOnClickListener(v -> {
            setCurrentClickPosition(position);
            if(onClickListener!=null){
                onClickListener.onItemClick(announcement);
            }
        });
        Date date= DateUtils.dateParse(announcement.getEndTime(),"yyyy-MM-dd HH:mm:ss");
        if((new Date()).after(date)){
            holder.setTextColor(R.id.tv_content,mContext.getResources().getColor(R.color.dark_909399));
            holder.setTextColor(R.id.tv_date,mContext.getResources().getColor(R.color.dark_909399));
        }else {

            holder.setTextColor(R.id.tv_content,mContext.getResources().getColor(R.color.black_2f3234));
            holder.setTextColor(R.id.tv_date,mContext.getResources().getColor(R.color.blue_0f6eff));
        }
    }
}
